#include "../include/log/log_sink.hpp"
#include "../include/log/log_format.hpp"
#include <unistd.h>

int main()
{
    log_system::LogMessage message(log_system::LogLevel::INFO, "test_log_sink.cc", 6, "root", "日志接收器测试!!!");
    log_system::Formatter formatter;
    std::string str = formatter.format(message);

    // log_system::LogSink::pointer stdout_ptr = log_system::LogSinkFactory::create<log_system::StdoutLogSink>();
    // log_system::LogSink::pointer file_ptr = log_system::LogSinkFactory::create<log_system::SpecifyFileLogSink>("./logfile/test.log");
    // log_system::LogSink::pointer scrollfilebusize_ptr = log_system::LogSinkFactory::create<log_system::ScrollFileBySizeLogSink>("./logfile/scrollbysize-", 1024 * 1024);

    // stdout_ptr->log(str.c_str(), str.size()); // 标准输出
    // file_ptr->log(str.c_str(), str.size());   // 指定文件

    // size_t current_size = 0;
    // size_t count = 0;
    // while (current_size < 1024 * 1024 * 10)
    // {
    //     std::string tmp = str + std::to_string(count++);        
    //     scrollfilebusize_ptr->log(tmp.c_str(), tmp.size());
    //     current_size += tmp.size();
    // }

    log_system::LogSink::pointer scrollfilebytime_ptr = log_system::LogSinkFactory::create<log_system::ScrollFileByTimeLogSink>("./logfile/scrollbytime-", log_system::ScrollFileByTimeLogSink::GAP_MINUTE);
    time_t old_time = log_system::utility::Date::getTime();

    while(log_system::utility::Date::getTime() < old_time + 5) // 五秒写入五个文件
    {
        scrollfilebytime_ptr->log(str.c_str(), str.size());
    }

    return 0;
}
